package cn.com.api.controller;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.api.entity.ApiT_enums;
import cn.com.api.entity.ApiU_match;
import cn.com.api.entity.ApiU_match_prize;
import cn.com.api.entity.ApiU_match_vote;
import cn.com.api.entity.ApiU_match_works;
import cn.com.api.service.ApiT_enumsService;
import cn.com.api.service.ApiU_matchService;
import cn.com.api.service.ApiU_match_prizeService;
import cn.com.api.service.ApiU_match_voteService;
import cn.com.api.service.ApiU_match_worksService;
import cn.com.api.service.CheckService;
import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_API + "u_match/")
public class ApiU_matchController {

	@Autowired
	private ApiU_matchService apiU_matchService;

	@Autowired
	private ApiU_match_prizeService apiU_match_prizeService;

	@Autowired
	private ApiU_match_worksService apiU_match_worksService;

	@Autowired
	private ApiU_match_voteService apiU_match_voteService;

	@Autowired
	private ApiT_enumsService apiT_enumsService;

	private static Logger logger = Logger.getLogger(ApiU_matchController.class);

	@Autowired
	private CheckService checkService;

	/**
	 * 根据用户ID获取赛事主页数据
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_match-homepage")
	public void findU_match_homepage(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("user_id", user_id);
			params.put("token", token);
			if (checkService.checkToken(user_id, token, map)) {
				SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
				Date date = new Date();
				Map<String, Object> homepageMap = new HashMap<String, Object>();
				List<Map<String, Object>> listVoteMap = new ArrayList<Map<String, Object>>();
				List<Map<String, Object>> listJoinMap = new ArrayList<Map<String, Object>>();
				List<Map<String, Object>> listNominateMap = new ArrayList<Map<String, Object>>();
				List<Map<String, Object>> listWinMap = new ArrayList<Map<String, Object>>();

				// 获取用户投票的作品列表
				List<ApiU_match> list_vote = apiU_matchService.findU_api_matchs_vote(params);

				for (ApiU_match apiU_match : list_vote) {
					homepageMap = new HashMap<String, Object>();
					try {

						Date pend_time = sd.parse(apiU_match.getPend_time());
						Date pstart_time = sd.parse(apiU_match.getPstart_time());
						Date vend_time = sd.parse(apiU_match.getVend_time());
						Date vstart_time = sd.parse(apiU_match.getVstart_time());
						Date result_time = sd.parse(apiU_match.getResult_time());

						if (getCurrDateBoolean(pstart_time, pend_time, date)) {
							homepageMap.put("type", "1");
						} else if (getCurrDateBoolean(vstart_time, vend_time, date)) {
							homepageMap.put("type", "2");
						} else if (date.getTime() > result_time.getTime()) {
							homepageMap.put("type", "3");
						} else if (getCurrDateBoolean(pend_time, vstart_time, date)) {
							homepageMap.put("type", "4");
						} else if (getCurrDateBoolean(vend_time, result_time, date)) {
							homepageMap.put("type", "5");
						}
					} catch (Exception e) {
						homepageMap.put("type", "");
					}

					homepageMap.put("match_id", apiU_match.getMatch_id());
					homepageMap.put("match_name", apiU_match.getMatch_name());
					homepageMap.put("thumbnail", apiU_match.getThumbnail());
					homepageMap.put("match_cate", apiU_match.getMatch_cate());
					listVoteMap.add(homepageMap);
				}

				// 获取用户参赛的赛事
				List<ApiU_match> list_join = apiU_matchService.findU_api_matchs_join(params);
				for (ApiU_match apiU_match : list_join) {
					homepageMap = new HashMap<String, Object>();
					homepageMap.put("match_id", apiU_match.getMatch_id());
					homepageMap.put("match_name", apiU_match.getMatch_name());
					homepageMap.put("thumbnail", apiU_match.getThumbnail());
					homepageMap.put("match_cate", apiU_match.getMatch_cate());
					try {

						Date pend_time = sd.parse(apiU_match.getPend_time());
						Date pstart_time = sd.parse(apiU_match.getPstart_time());
						Date vend_time = sd.parse(apiU_match.getVend_time());
						Date vstart_time = sd.parse(apiU_match.getVstart_time());
						Date result_time = sd.parse(apiU_match.getResult_time());

						if (getCurrDateBoolean(pstart_time, pend_time, date)) {
							homepageMap.put("type", "1");
						} else if (getCurrDateBoolean(vstart_time, vend_time, date)) {
							homepageMap.put("type", "2");
						} else if (date.getTime() > result_time.getTime()) {
							homepageMap.put("type", "3");
						} else if (getCurrDateBoolean(pend_time, vstart_time, date)) {
							homepageMap.put("type", "4");
						} else if (getCurrDateBoolean(vend_time, result_time, date)) {
							homepageMap.put("type", "5");
						}
					} catch (Exception e) {
						homepageMap.put("type", "");
					}
					listJoinMap.add(homepageMap);
				}

				List<ApiT_enums> cate = apiT_enumsService.findT_enumssByItem_key("match_cates_list");
				List<ApiT_enums> cate_list = apiT_enumsService.findT_enumssByParent_id(cate.get(0).getId() + "");
				// 获取赛事推荐列表(该用户未参与的)
				List<ApiU_match> list_nominate = apiU_matchService.findU_api_matchs_nominate(params);
				// for (ApiU_match apiU_match : list_nominate) {
				// homepageMap = new HashMap<String, Object>();
				// homepageMap.put("match_id", apiU_match.getMatch_id());
				// homepageMap.put("match_name", apiU_match.getMatch_name());
				// homepageMap.put("thumbnail", apiU_match.getThumbnail());
				// homepageMap.put("match_cate", apiU_match.getMatch_cate());
				// listNominateMap.add(homepageMap);
				// }

				List<ApiU_match> list_win = apiU_matchService.findU_api_matchs_win(params);
				for (ApiU_match apiU_match : list_win) {
					homepageMap = new HashMap<String, Object>();
					homepageMap = new HashMap<String, Object>();
					homepageMap.put("match_id", apiU_match.getMatch_id());
					homepageMap.put("match_name", apiU_match.getMatch_name());
					homepageMap.put("thumbnail", apiU_match.getThumbnail());
					homepageMap.put("match_cate", apiU_match.getMatch_cate());
					listWinMap.add(homepageMap);
				}

				for (ApiT_enums apiT_enums : cate_list) {
					homepageMap = new HashMap<String, Object>();
					homepageMap.put("match_cate_id", apiT_enums.getItem_value());
					homepageMap.put("match_cate", apiT_enums.getDisplay_name());
					homepageMap.put("thumbnail", "");
					listNominateMap.add(homepageMap);
				}

				result.put("list_win", listWinMap);
				result.put("list_vote", listVoteMap);
				result.put("list_join", listJoinMap);
				result.put("list_nominate", listNominateMap);

				map.put("datas", result);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 赛事详情
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_match-detail")
	@Transactional
	public @ResponseBody Map<String, Object> findU_match_detail(HttpServletRequest request,
			HttpServletResponse response, String user_id, String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {

			/*
			 * String u_id = request.getParameter("u_id"); String token =
			 * request.getParameter("token");
			 */
			String match_id = request.getParameter("match_id");
			String type = request.getParameter("type");
			Map<String, Object> params = new HashMap<String, Object>();
			Map<String, Object> result = new HashMap<String, Object>();
			// params.put("u_id", user_id);
			params.put("user_id", user_id);
			params.put("match_id", match_id);
			params.put("token", token);

			if (checkService.checkToken(user_id, token, map)) {

				Map<String, Object> detailMap = new HashMap<String, Object>();
				List<Map<String, Object>> listPrizeMap = new ArrayList<Map<String, Object>>();
				List<Map<String, Object>> listMatchMap = new ArrayList<Map<String, Object>>();
				List<Map<String, Object>> listWorksMap = new ArrayList<Map<String, Object>>();
				// 获取赛事详情
				if ("1".equals(type)) {
					int enroll_status = apiU_matchService.findU_enroll_status(params);
					int num = apiU_matchService.findU_api_matchs_worksnum(match_id);
					List<ApiU_match_prize> list_prize = apiU_match_prizeService.findU_match_prizesByMatchId(match_id);
					for (ApiU_match_prize apiU_match_prize : list_prize) {
						detailMap = new HashMap<String, Object>();
						detailMap.put("prize_name", apiU_match_prize.getPrize_name());
						detailMap.put("prize_num", apiU_match_prize.getPrize_num());
						detailMap.put("prize_money", apiU_match_prize.getPrize_money());
						detailMap.put("winner_count", apiU_match_prize.getWinner_count());
						listPrizeMap.add(detailMap);
					}

					List<ApiU_match> list = apiU_matchService.findU_matchs_condition(params);
					for (ApiU_match apiU_match : list) {
						detailMap = new HashMap<String, Object>();
						detailMap.put("match_id", apiU_match.getMatch_id());
						detailMap.put("match_name", apiU_match.getMatch_name());
						detailMap.put("thumbnail", apiU_match.getThumbnail());
						detailMap.put("pend_time", apiU_match.getPend_time());
						detailMap.put("vend_time", apiU_match.getVend_time());
						detailMap.put("match_introduce", apiU_match.getMatch_introduce());
						detailMap.put("match_rules", apiU_match.getMatch_rules());
						detailMap.put("bonus_amount", apiU_match.getBonus_amount());
						detailMap.put("win_amount", apiU_match.getWin_amount());
						detailMap.put("guess_amount", apiU_match.getGuess_amount());
						listMatchMap.add(detailMap);
					}
					result.put("list_match", listMatchMap);
					result.put("works_num", num);
					result.put("list_prize", listPrizeMap);
					result.put("enroll_status", enroll_status);
				} else if ("2".equals(type)) {
					int vote_status = apiU_matchService.findU_vote_status(params);

					List<ApiU_match> list = apiU_matchService.findU_matchs_condition(params);
					for (ApiU_match apiU_match : list) {
						detailMap = new HashMap<String, Object>();
						detailMap.put("match_id", apiU_match.getMatch_id());
						detailMap.put("match_name", apiU_match.getMatch_name());
						detailMap.put("thumbnail", apiU_match.getThumbnail());
						detailMap.put("pend_time", apiU_match.getPend_time());
						detailMap.put("vend_time", apiU_match.getVend_time());
						detailMap.put("match_introduce", apiU_match.getMatch_introduce());
						detailMap.put("match_rules", apiU_match.getMatch_rules());
						detailMap.put("bonus_amount", apiU_match.getBonus_amount());
						detailMap.put("win_amount", apiU_match.getWin_amount());
						detailMap.put("guess_amount", apiU_match.getGuess_amount());
						listMatchMap.add(detailMap);
					}
					result.put("list_match", listMatchMap);
					int num = apiU_matchService.findU_api_matchs_votenum(match_id);
					result.put("vote_num", num);
					result.put("vote_status", vote_status);
				} else if ("3".equals(type)) {
					// 获得各个奖项作品列表，根据投票人数排序
					int num = apiU_matchService.findU_api_matchs_votenum(match_id);
					List<ApiU_match_works> list_works = apiU_match_worksService
							.findU_match_worksByMatchId(Integer.parseInt(match_id));
					for (ApiU_match_works apiU_match_works : list_works) {
						detailMap = new HashMap<String, Object>();
						detailMap.put("works_name", apiU_match_works.getWorks_name());
						detailMap.put("works_url", apiU_match_works.getWorks_url());
						detailMap.put("vedio_url", apiU_match_works.getVedio_url());
						detailMap.put("join_name", apiU_match_works.getJoin_name());
						detailMap.put("vote_number", apiU_match_works.getExt1());
						detailMap.put("works_number", apiU_match_works.getExt2());
						listWorksMap.add(detailMap);
					}
					result.put("list_works", listWorksMap);
					result.put("vote_num", num);
					Map res = getStatistics(params);

					result.put("list_statistics", (List) res.get("list_statistics"));
					result.put("vote_num", (Integer) res.get("vote_num"));
					result.put("works_num", (Integer) res.get("works_num"));
					result.put("prize_num", (Integer) res.get("prize_num"));
					List<Map<String, Object>> list_great = apiU_matchService.findU_match_great(params);

					result.put("list_great", list_great);
				}

				result.put("type", type);
				map.put("datas", result);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		// JsonUtil.printJson(response, JsonUtil.object2json(map));
		return map;
	}

	/**
	 * 详情
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findMatchDetail")
	@Transactional
	public @ResponseBody Map<String, Object> findMatchDetail(HttpServletRequest request, HttpServletResponse response,
			String match_id, String user_id, String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("user_id", user_id);
			params.put("match_id", match_id);
			params.put("token", token);

			if (checkService.checkToken(user_id, token, map)) {
				map.put("match_id", match_id);
				List<ApiU_match> match = apiU_matchService.findU_matchs_condition(map);
				map.clear();
				map.put("datas", match.get(0));
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}
		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.clear();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}
		return map;

	}

	/**
	 * 根据搜索关键字查询赛事列表
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_match-search")
	public void findU_match_search(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {

			String match_name = request.getParameter("match_name");
			Map<String, Object> params = new HashMap<String, Object>();

			params.put("user_id", user_id);
			params.put("match_name", match_name);
			params.put("token", token);
			if (checkService.checkToken(user_id, token, map)) {
				Map<String, Object> searchMap = new HashMap<String, Object>();
				List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
				SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
				Date date = new Date();
				// 获取赛事列表根据搜索模糊查询
				List<ApiU_match> list = apiU_matchService.findU_matchsByMatchName(params);
				for (ApiU_match apiU_match : list) {

					searchMap = new HashMap<String, Object>();
					Date pend_time = sd.parse(apiU_match.getPend_time());
					Date pstart_time = sd.parse(apiU_match.getPstart_time());
					Date vend_time = sd.parse(apiU_match.getVend_time());
					Date vstart_time = sd.parse(apiU_match.getVstart_time());
					Date result_time = sd.parse(apiU_match.getResult_time());

					if (getCurrDateBoolean(pend_time, pstart_time, date)) {
						searchMap.put("type", "1");
					} else if (getCurrDateBoolean(vstart_time, vend_time, date)) {
						searchMap.put("type", "2");
					} else if (date.getTime() > result_time.getTime()) {
						searchMap.put("type", "3");
					} else {
						searchMap.put("type", "");
					}
					searchMap.put("match_id", apiU_match.getMatch_id());
					searchMap.put("match_name", apiU_match.getMatch_name());
					searchMap.put("thumbnail", apiU_match.getThumbnail());

					listMap.add(searchMap);
				}

				map.put("datas", listMap);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 获取赛事时间段类型获取赛事列表
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_match-type")
	public void findU_match_type(HttpServletRequest request, HttpServletResponse response, String user_id, String token)
			throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {

			/**/
			String type = request.getParameter("type");
			String match_cate = request.getParameter("match_cate");
			Map<String, Object> params = new HashMap<String, Object>();

			params.put("user_id", user_id);
			params.put("type", type);
			params.put("token", token);
			params.put("match_cate", match_cate);
			if (checkService.checkToken(user_id, token, map)) {
				Map<String, Object> typeMap = new HashMap<String, Object>();
				List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
				// 获取赛事时间段类型获取赛事列表
				List<ApiU_match> list = apiU_matchService.findU_matchs_enroll_condition(params);
				for (ApiU_match apiU_match : list) {
					typeMap = new HashMap<String, Object>();
					typeMap.put("match_id", apiU_match.getMatch_id());
					typeMap.put("match_name", apiU_match.getMatch_name());
					typeMap.put("thumbnail", apiU_match.getThumbnail());
					typeMap.put("type", type);
					listMap.add(typeMap);
				}

				map.put("datas", listMap);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 赛事统计
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_match-statistics")
	public void findU_match_statistics(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {

			String match_id = request.getParameter("match_id");
			Map<String, Object> params = new HashMap<String, Object>();

			params.put("user_id", user_id);
			params.put("token", token);
			params.put("match_id", match_id);
			if (checkService.checkToken(user_id, token, map)) {
				Map<String, Object> prizeMap = new HashMap<String, Object>();
				List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
				List<Map<String, Object>> list_prize_info = new ArrayList<Map<String, Object>>();
				List<ApiU_match_prize> list_prize = apiU_match_prizeService.findU_match_prizesByMatchId(match_id);
				List<Map<String, Object>> list = apiU_match_worksService.findU_matchs_statistics_condition(params);
				int j = 0;
				for (ApiU_match_prize apiU_match_prize : list_prize) {
					prizeMap = new HashMap<String, Object>();
					int start = j;
					list_prize_info = new ArrayList<Map<String, Object>>();
					j += apiU_match_prize.getPrize_num();
					int end = j;
					prizeMap.put("prize_name", apiU_match_prize.getPrize_name());
					prizeMap.put("prize_num", apiU_match_prize.getPrize_num());
					int i = 0;

					for (Map<String, Object> map2 : list) {
						if (i >= start && i < end) {
							list_prize_info.add(map2);
						}
						i++;
					}

					prizeMap.put("prize_list", list_prize_info);
					listMap.add(prizeMap);
				}

				Map<String, Object> result = apiU_matchService.findU_api_matchs_prizeInfo(match_id);
				result.put("list", listMap);
				result.put("prize_all_sum", j);
				map.put("datas", result);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 谁给TA投了票
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping("findU_match-vote-who")
	public void findU_match_vote_who(HttpServletRequest request, HttpServletResponse response, String user_id,
			String token) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		try {

			String works_id = request.getParameter("works_id");
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("user_id", user_id);
			params.put("works_id", works_id);
			params.put("token", token);
			if (checkService.checkToken(user_id, token, map)) {
				Map<String, Object> voteMap = new HashMap<String, Object>();
				List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();

				List<ApiU_match_vote> list = apiU_match_voteService.findU_match_votesByWorksId(works_id);
				for (ApiU_match_vote apiU_match_vote : list) {
					voteMap = new HashMap<String, Object>();
					voteMap.put("c_nick", apiU_match_vote.getExt1());
					voteMap.put("c_avatar", apiU_match_vote.getC_avatar());
					listMap.add(voteMap);
				}

				map.put("datas", listMap);
				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "查询成功！");
			}

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
			map.put(Utils.MESSAGE, "系统异常！");
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));

	}

	/**
	 * 
	 * @param startDate
	 * @param endDate
	 * @param curDate
	 * @return
	 */
	private boolean getCurrDateBoolean(Date startDate, Date endDate, Date curDate) {
		if (curDate.getTime() > startDate.getTime() && curDate.getTime() < endDate.getTime()) {
			return true;
		}
		return false;

	}

	private Map getStatistics(Map<String, Object> params) {
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			Map<String, Object> prizeMap = new HashMap<String, Object>();
			List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
			List<Map<String, Object>> list_prize_info = new ArrayList<Map<String, Object>>();
			List<ApiU_match_prize> list_prize = apiU_match_prizeService
					.findU_match_prizesByMatchId((String) params.get("match_id"));

			int prize_count = apiU_match_prizeService.findU_match_prize_countByMatchId((String) params.get("match_id"));

			ApiU_match_prize ApiU_match_prize = new ApiU_match_prize();
			ApiU_match_prize.setPrize_id(0);
			ApiU_match_prize.setPrize_name("未得奖");
			ApiU_match_prize.setPrize_count(prize_count);
			list_prize.add(ApiU_match_prize);
			List<Map<String, Object>> list = apiU_match_worksService.findU_match_statistics(params);
			for (ApiU_match_prize apiU_match_prize : list_prize) {
				prizeMap = new HashMap<String, Object>();

				list_prize_info = new ArrayList<Map<String, Object>>();

				prizeMap.put("prize_name", apiU_match_prize.getPrize_name());
				prizeMap.put("prize_num", apiU_match_prize.getPrize_num());
				prizeMap.put("prize_id", apiU_match_prize.getPrize_id());
				prizeMap.put("prize_count", apiU_match_prize.getPrize_count());

				for (Map<String, Object> map2 : list) {
					/*
					 * if (i >= start && i < end) { list_prize_info.add(map2); }
					 */
					BigDecimal prize_id = BigDecimal.ZERO;
					if (map2.get("prize_id") != null) {
						prize_id = (BigDecimal) map2.get("prize_id");
					}

					if (new BigDecimal(apiU_match_prize.getPrize_id()).compareTo(prize_id) == 0) {
						list_prize_info.add(map2);
					}
				}

				prizeMap.put("prize_list", list_prize_info);
				listMap.add(prizeMap);
			}

			result = apiU_matchService.findU_api_matchs_prizeInfo((String) params.get("match_id"));
			result.put("list_statistics", listMap);

		} catch (Exception e) {
			logger.error(e);
			e.printStackTrace();

		}
		return result;
	}

}
